﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Angel.XNA.StringFormatImg;
namespace RPGGameLibrary
{
    public class Text:GUICom
    {
        //private GraphicsDeviceManager graphics;
        private SpriteBatch ForegroundBatch;
        private Texture2D SpriteTexture;
        public string TextString;
        public override void Start(Map _map)
        {
            LocalMap = _map;
            TextString = "error";
           
        }
        public  void Start(Map _map,string _Text)
        {
            LocalMap = _map;
            TextString = _Text;

        }
        public override void Draw( GraphicsDeviceManager graphics)
        {  
 
            //如果为了输出一行文字而专门初始化就太麻烦了，所以干脆用了这种方法
           if (SpriteTexture==null)
           {
               ForegroundBatch = new SpriteBatch(graphics.GraphicsDevice);
               StringFormatImg outitext = new StringFormatImg(TextString, "宋体", 9, Color.Pink);
               SpriteTexture = Texture2D.FromStream(graphics.GraphicsDevice, outitext.Out2D());
           }
            
          
            // TODO: Add your drawing code here
            ForegroundBatch.Begin();
            Vector2 pos = new Vector2(100, 100);
            ForegroundBatch.Draw(SpriteTexture, pos, Color.White);
            ForegroundBatch.End();
        }
    }
}
